﻿using DLUProject.Domain;
using DLUProject.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class KTX_ListTinTuc : BaseUserControl
{
    public IServices<TinTuc> _service { get; set; }
    public ModuleInstanceExtension moduleInstance { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        Page.Title = "Tin tức - Hoạt động";
        if (!IsPostBack)
        {

            List<ModuleInstance> modulesLeft = moduleInstance.GetByModulePosition(ModulePosition.Left);
            foreach (var item in modulesLeft)
            {
                BaseUserControl userControlX = (BaseUserControl)LoadControl(item.Module.Path);

                if (userControlX != null)
                {
                    userControlX.ModuleID = item.ModuleInstanceID.ToString();
                    userControlX.Title = item.Title;
                    userControlX.Params = item.Params;
                    userControlX.ShowHide = item.IsActive;
                    userControlX.State = item.State;
                    PlaceHolderLeft.Controls.Add(userControlX);
                }
            }

            int total = 0;
            int pageSize = 10;
            int pageNum = 1;
            if (Request.QueryString[PagingControl1.QueryStringKey] != null)
            {
                pageNum = int.Parse(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
            }
            else pageNum = 1;

            var items = _service.All().AsQueryable();
            rptItems.DataSource = _service.Paging(items, pageSize, pageNum, out total);
            rptItems.DataBind();
            PagingControl1.TotalRecord = total;
            PagingControl1.CurrentPage = pageNum;
            PagingControl1.PageSize = pageSize;
        }
    }
}